package leetcode;

import java.util.HashMap;

/**
 * @author ht
 * @create 2025-06-19 22:30
 * @desc
 **/
public class T383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        HashMap<String, Integer> map  = new HashMap<>();
        for (int i = 0; i < magazine.length(); i++) {
            String s = String.valueOf(magazine.charAt(i));
            if(map.containsKey(s)) {
                map.put(s, map.get(s) + 1);
            } else {
                map.put(s, 1);
            }
        }

        for (int i = 0; i < ransomNote.length(); i++) {
            String s = String.valueOf(ransomNote.charAt(i));
            if(map.containsKey(s) && map.get(s) > 0) {
                map.put(s, map.get(s) - 1);
            } else {
                return false;
            }
        }
        return true;
    }

}
